<?php defined('IN_YuLin') || exit('NO PERMIT!'); ?>
{template index/header}
    <div class="subnav">
        <a href="">首页</a> &gt; <a href="">活动管理</a> &gt; <a href="">活动管理</a>
    </div>
    
    <div class="main-inner">
        <div class="x-body">
            <div class="tablefilter">
                <div class="tablebutton">
                    <a href="?m={$m}&c={$c}&a=send" class=""><i class="fa fa-plus"></i>发送活动</a>
                    <a href="javascript:void(0);" class="checkAll"><i class="fa fa-check"></i>全选</a>
                    <a href="javascript:void(0);" class="delete"><i class="fa fa-trash"></i>删除</a>      
                </div>
                <div class="tableButton">
                    <input type="submit" name="search" class="layui-btn" value="保存更改">
                </div>
            </div>

            <table class="layui-table">
                <thead>
                    <tr>
                        <th>选择</th>
                        <th>活动名称</th>
                        <th>活动类型</th>
                        <th>添加时间</th>
                        <th>操作</th>
                        <th>排序</th>
                    </tr>
                </thead>
                <tbody id="datalist">
                    {loop $data as $k=>$v}
                    	<tr id="tr_{$v['id']}">
                            <td>
                                <input type="checkbox" name="ids[{$k}]" class="del" value="{$v['id']}" />
                            </td>
                            <td><a href="?m={$m}&c={$c}&a=send&o={$v['id']}">{$v['title']}</a></td>
                            <td>{$v['source']}</td>
                            <td>{date("Y-m-d H:i:s",$v['inputtime'])}</td>
                            <td><a href="?m={$m}&c={$c}&a=edit&o={$v['id']}&_s={$v['status']}" data-status="{$v['status']}">{if $v['status'] == '1'}禁用{else}启用{/if}</a></td>
                            <td></td>
                        </tr>
                    {/loop}
                </tbody>
            </table>
            <div class="layui-clear">
                <div id="pages" class="layui-laypage">{$multi}</div>
            </div>
        </div>
    </div>
    <script>
        $(function(){
            var checkBtn = false;
            $(".checkAll").on('click',function(){
                if(!checkBtn){
                    $("input[name^='ids']").prop('checked',true);
                    checkBtn = true;
                }else{
                    $("input[name^='ids']").prop('checked',false);
                    checkBtn = false;
                }
            })

            $(".delete").on('click',function(){
                var ids = [];
                $("input[name^='ids']:checked").map(function(){
                    ids.push($(this).val());
                });
                ids = ids.join(', ');
                if(!ids.length){
                    alert('当前没有选中元素');return;
                }
                var oUrl = '?m={$m}&c={$c}&a=delete';
                $.ajaxSetup({async:false});
                $.post(oUrl,{ids:ids},function(res){
                    alert("成功删除"+res+"条记录");
                    $("input[name^='ids']:checked").map(function(){
                        $(this).parent().parent().remove();
                    });
                });
            })
        });
    </script>
{template index/footer}
